﻿using MySql.Data.MySqlClient;
using System;
using System.Configuration;
using System.Threading.Tasks;

public class LibraryDbContext : IDisposable
{
    private readonly MySqlConnection _connection;

    public LibraryDbContext()
    {
        var connectionString = ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString;
        _connection = new MySqlConnection(connectionString);
        _connection.Open();
    }

    public MySqlCommand CreateCommand()
    {
        return _connection.CreateCommand();
    }

    public async Task<MySqlTransaction> BeginTransactionAsync()
    {
        return await _connection.BeginTransactionAsync();
    }

    public void Dispose()
    {
        _connection?.Close();
        _connection?.Dispose();
    }
}